<?php
namespace Common\Controller;
use Think\Controller;

/**
 * 短信API管理
 * Class smsApiController
 * @package Admin\Controller
 */
class SmsApiController extends Controller {


    private $queryUrl = 'http://api.smsbao.com/query?u=USERNAME&p=PASSWORD';
    static $smsUrl = 'http://api.smsbao.com/sms?u=USERNAME&p=PASSWORD&m=PHONE&c=CONTENT';

    static public function SendMsg($phone, $msg){

        $smsApi = M("sms_api")->where(array("token"=>"default"))->find();
        if(!$smsApi){
            return array("status"=>false,"info"=>"配置信息未找到");
        }

        $request = strtr(self::$smsUrl, [
            "USERNAME" => $smsApi['username'],
            "PASSWORD" => md5($smsApi["passwd"]),
            "PHONE" => $phone,
            "CONTENT" => $msg,
        ]);
        $res = file_get_contents($request);
        if($res=='0'){
            return array("status"=>true);
        }else{
            return array("status"=>false,"info"=>$res);
        }
    }

}